package com.example.leetcode.StackSimple;

import java.util.Stack;

public class C_最小栈 {
}

class MinStack {
    Stack<Integer> stack;
    Stack<Integer> stackMin;

    /**
     * initialize your data structure here.
     */
    public MinStack() {
        stack = new Stack<>();
        stackMin = new Stack<>();
    }

    public void push(int x) {
        stack.push(x);
        if (stackMin.isEmpty()) {
            stackMin.push(x);
        } else {
            Integer peek = stackMin.peek();
            stackMin.push(peek < x ? peek : x);
        }
    }

    public void pop() {
        stack.pop();
        stackMin.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return stackMin.peek();
    }
}
